/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package formularios;

import catalogodecarros.Catalogodecarros;
import javax.swing.JOptionPane;

/**
 *
 * @author Saul
 */
public class frmcatalogodecarros extends javax.swing.JFrame {

    /**
     * Creates new form frmcatalogodecarros
     */
    public frmcatalogodecarros() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        lblcatalogo = new javax.swing.JLabel();
        lblcodigo = new javax.swing.JLabel();
        lblplaca = new javax.swing.JLabel();
        lblmarca = new javax.swing.JLabel();
        lblprecio = new javax.swing.JLabel();
        lblano = new javax.swing.JLabel();
        lblseguro = new javax.swing.JLabel();
        optrustico = new javax.swing.JRadioButton();
        optsedan = new javax.swing.JRadioButton();
        optdeportivo = new javax.swing.JRadioButton();
        opt4x2 = new javax.swing.JRadioButton();
        opt4x4 = new javax.swing.JRadioButton();
        btnguardar = new javax.swing.JButton();
        btnmodificar = new javax.swing.JButton();
        btneliminar = new javax.swing.JButton();
        btnconsultar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        chkseguro = new javax.swing.JCheckBox();
        txtcodigo = new javax.swing.JTextField();
        txtplaca = new javax.swing.JTextField();
        txtprecio = new javax.swing.JTextField();
        cmbmarca = new javax.swing.JComboBox();
        txtano = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        lblcatalogo.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        lblcatalogo.setText("Catalogo de Vehiculos");
        getContentPane().add(lblcatalogo, new org.netbeans.lib.awtextra.AbsoluteConstraints(312, 11, -1, -1));

        lblcodigo.setText("Codigo:");
        getContentPane().add(lblcodigo, new org.netbeans.lib.awtextra.AbsoluteConstraints(89, 51, -1, -1));

        lblplaca.setText("Placa:");
        getContentPane().add(lblplaca, new org.netbeans.lib.awtextra.AbsoluteConstraints(89, 89, -1, -1));

        lblmarca.setText("Marca:");
        getContentPane().add(lblmarca, new org.netbeans.lib.awtextra.AbsoluteConstraints(89, 121, -1, -1));

        lblprecio.setText("Precio:");
        getContentPane().add(lblprecio, new org.netbeans.lib.awtextra.AbsoluteConstraints(89, 156, -1, -1));

        lblano.setText("Año:");
        getContentPane().add(lblano, new org.netbeans.lib.awtextra.AbsoluteConstraints(89, 194, -1, -1));

        lblseguro.setText("Posee seguro?");
        getContentPane().add(lblseguro, new org.netbeans.lib.awtextra.AbsoluteConstraints(89, 229, -1, -1));

        buttonGroup1.add(optrustico);
        optrustico.setSelected(true);
        optrustico.setText("Rustico");
        getContentPane().add(optrustico, new org.netbeans.lib.awtextra.AbsoluteConstraints(89, 268, -1, -1));

        buttonGroup1.add(optsedan);
        optsedan.setText("Sedan");
        getContentPane().add(optsedan, new org.netbeans.lib.awtextra.AbsoluteConstraints(89, 291, -1, -1));

        buttonGroup1.add(optdeportivo);
        optdeportivo.setText("Deportivo");
        getContentPane().add(optdeportivo, new org.netbeans.lib.awtextra.AbsoluteConstraints(89, 314, -1, -1));

        buttonGroup2.add(opt4x2);
        opt4x2.setSelected(true);
        opt4x2.setText("4x2");
        getContentPane().add(opt4x2, new org.netbeans.lib.awtextra.AbsoluteConstraints(212, 268, 71, -1));

        buttonGroup2.add(opt4x4);
        opt4x4.setText("4x4");
        getContentPane().add(opt4x4, new org.netbeans.lib.awtextra.AbsoluteConstraints(212, 291, -1, -1));

        btnguardar.setText("Guardar");
        btnguardar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnguardarMouseClicked(evt);
            }
        });
        getContentPane().add(btnguardar, new org.netbeans.lib.awtextra.AbsoluteConstraints(270, 350, -1, -1));

        btnmodificar.setText("Modificar");
        btnmodificar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnmodificarMouseClicked(evt);
            }
        });
        getContentPane().add(btnmodificar, new org.netbeans.lib.awtextra.AbsoluteConstraints(350, 350, -1, -1));

        btneliminar.setText("Eliminar");
        btneliminar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btneliminarMouseClicked(evt);
            }
        });
        getContentPane().add(btneliminar, new org.netbeans.lib.awtextra.AbsoluteConstraints(430, 350, -1, -1));

        btnconsultar.setText("Consultar");
        getContentPane().add(btnconsultar, new org.netbeans.lib.awtextra.AbsoluteConstraints(350, 380, -1, -1));

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        getContentPane().add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(139, 415, -1, 109));
        getContentPane().add(chkseguro, new org.netbeans.lib.awtextra.AbsoluteConstraints(177, 229, -1, -1));
        getContentPane().add(txtcodigo, new org.netbeans.lib.awtextra.AbsoluteConstraints(177, 52, 136, -1));

        txtplaca.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtplacaActionPerformed(evt);
            }
        });
        getContentPane().add(txtplaca, new org.netbeans.lib.awtextra.AbsoluteConstraints(177, 83, 136, -1));
        getContentPane().add(txtprecio, new org.netbeans.lib.awtextra.AbsoluteConstraints(177, 153, 136, -1));

        cmbmarca.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Toyota", "Nissa", "Honda", "Mitsubishi", "BMW" }));
        getContentPane().add(cmbmarca, new org.netbeans.lib.awtextra.AbsoluteConstraints(177, 115, -1, -1));
        getContentPane().add(txtano, new org.netbeans.lib.awtextra.AbsoluteConstraints(177, 191, 73, -1));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txtplacaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtplacaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtplacaActionPerformed
    private String getSeguro(){
        if(this.chkseguro.isSelected()==true){
            return "S";
        }else{
            return "N";
        }
    }
    private String getTipo(){
        if(this.optrustico.isSelected()==true){
            return "rustico";
        }else if (this.optsedan.isSelected()==true){
            return "sedan";
        }else{
            return "deportivo";
        }
    }
    private String getTraccion(){
        if(this.opt4x2.isSelected()==true){
            return "4x2";
        }else{
            return "4x4";
        }
    }
    private void btnguardarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnguardarMouseClicked
        // CODIGO PARA QUE EL BOTON GUARDE
        int codigo=Integer.parseInt(this.txtcodigo.getText());
        int placa=Integer.parseInt(this.txtplaca.getText());
        String marca=this.cmbmarca.getSelectedItem().toString();
        int precio=Integer.parseInt(this.txtprecio.getText());
        int ano=Integer.parseInt(this.txtano.getText());
        String seguro=getSeguro();
        String tipo=getTipo();
        String traccion=getTraccion();
        Catalogodecarros em=new Catalogodecarros();
        em.guardar(codigo, placa, marca, precio, ano, seguro, tipo, traccion);
        JOptionPane.showMessageDialog(null, "GUARDO CORRECTAMENTE");    
    }//GEN-LAST:event_btnguardarMouseClicked

    private void btnmodificarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnmodificarMouseClicked
        // CODIGO PRA QUE EL BOTON MODIFIQUE
        int codigo=Integer.parseInt(this.txtcodigo.getText());
        int placa=Integer.parseInt(this.txtplaca.getText());
        String marca=this.cmbmarca.getSelectedItem().toString();
        int precio=Integer.parseInt(this.txtprecio.getText());
        int ano=Integer.parseInt(this.txtano.getText());
        String seguro=getSeguro();
        String tipo=getTipo();
        String traccion=getTraccion();
        Catalogodecarros em=new Catalogodecarros();
        em.modificar(codigo, placa, marca, precio, ano, seguro, tipo, traccion);
        JOptionPane.showMessageDialog(null, "MODIFICO CORRECTAMENTE"); 
    }//GEN-LAST:event_btnmodificarMouseClicked

    private void btneliminarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btneliminarMouseClicked
        // CODIGO PARA QUE EL BOTON ELIMINE
        int codigo=Integer.parseInt(this.txtcodigo.getText());
        Catalogodecarros em=new Catalogodecarros();
        em.eliminar(codigo);
        JOptionPane.showMessageDialog(null, "REGISTRO ELIMINADO");
    }//GEN-LAST:event_btneliminarMouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(frmcatalogodecarros.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(frmcatalogodecarros.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(frmcatalogodecarros.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(frmcatalogodecarros.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new frmcatalogodecarros().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnconsultar;
    private javax.swing.JButton btneliminar;
    private javax.swing.JButton btnguardar;
    private javax.swing.JButton btnmodificar;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.JCheckBox chkseguro;
    private javax.swing.JComboBox cmbmarca;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JLabel lblano;
    private javax.swing.JLabel lblcatalogo;
    private javax.swing.JLabel lblcodigo;
    private javax.swing.JLabel lblmarca;
    private javax.swing.JLabel lblplaca;
    private javax.swing.JLabel lblprecio;
    private javax.swing.JLabel lblseguro;
    private javax.swing.JRadioButton opt4x2;
    private javax.swing.JRadioButton opt4x4;
    private javax.swing.JRadioButton optdeportivo;
    private javax.swing.JRadioButton optrustico;
    private javax.swing.JRadioButton optsedan;
    private javax.swing.JTextField txtano;
    private javax.swing.JTextField txtcodigo;
    private javax.swing.JTextField txtplaca;
    private javax.swing.JTextField txtprecio;
    // End of variables declaration//GEN-END:variables
}
